/*
 * This file is part of aion-engine <aion-engine.com>
 *
 * aion-engine is private software: you can redistribute it and or modify
 * it under the terms of the GNU Lesser Public License as published by
 * the Private Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * aion-engine is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser Public License for more details.
 *
 * You should have received a copy of the GNU Lesser Public License
 * along with aion-engine.  If not, see <http://www.gnu.org/licenses/>.
 */
package com.aionengine.gameserver.utils.audit;

import com.aionengine.gameserver.configs.main.PunishmentConfig;
import com.aionengine.gameserver.model.gameobjects.player.Player;
import com.aionengine.gameserver.network.BannedMacManager;
import com.aionengine.gameserver.network.aion.serverpackets.SM_QUIT_RESPONSE;
import com.aionengine.gameserver.network.loginserver.LoginServer;
import com.aionengine.gameserver.services.PunishmentService;

/**
 * @author synchro2
 */
public class AutoBan {

    protected static void punishment(Player player, String message) {

        String reason = "AUTO " + message;
        String address = player.getClientConnection().getMacAddress();
        String accountIp = player.getClientConnection().getIP();
        int accountId = player.getClientConnection().getAccount().getId();
        int playerId = player.getObjectId();
        int time = PunishmentConfig.PUNISHMENT_TIME;
        int minInDay = 1440;
        int dayCount = (int) (Math.floor((double) (time / minInDay)));

        switch (PunishmentConfig.PUNISHMENT_TYPE) {
            case 1:
                player.getClientConnection().close(new SM_QUIT_RESPONSE(), false);
                break;
            case 2:
                PunishmentService.banChar(playerId, dayCount, reason);
                break;
            case 3:
                LoginServer.getInstance().sendBanPacket((byte) 1, accountId, accountIp, time, 0);
                break;
            case 4:
                LoginServer.getInstance().sendBanPacket((byte) 2, accountId, accountIp, time, 0);
                break;
            case 5:
                player.getClientConnection().closeNow();
                BannedMacManager.getInstance().banAddress(address, System.currentTimeMillis() + time * 60000, reason);
                break;
        }
    }
}